package com.tensquare.gathering.service;

import com.tensquare.gathering.dao.GatheringDao;
import com.tensquare.gathering.pojo.Gathering;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by WF on 2019/8/7 12:32
 */
@Transactional
@Service
public class GatheringService {
    @Autowired
    private GatheringDao gatheringDao;
    //清理缓存
    @CacheEvict(key = "#gathering.id")
    public void update(Gathering gathering){
        gatheringDao.save(gathering);
    }
    //存放方式：以id为key，以方法的返回结果为值放到缓存中
    @Cacheable(value = "gathering",key = "#id")
    public Gathering findById(String id) {
        return gatheringDao.findById(id).get();
    }
    //清理缓存
    @CacheEvict(key = "#id")
    public void delete(String id){
        gatheringDao.deleteById(id);
    }
}
